<?php
/*
 * Created on 2008-3-13
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 class Default_Service_Password{
 	// get a new salt - 8 hexadecimal characters long
	// current PHP installations should not exceed 8 characters
	// on dechex( mt_rand() )
	// but we future proof it anyway with substr()
	public static function getPasswordSalt()
	{
	    return substr( str_pad( dechex( mt_rand() ), 8, '0',STR_PAD_LEFT ), -8 );
	}
	
	// calculate the hash from a salt and a password
	public static function getPasswordHash( $salt, $password )
	{
	    return $salt . ( hash('whirlpool', $salt.$password) );
	}
	
	// compare a password to a hash
	public static function comparePassword( $password, $hash )
	{
	    $salt = substr( $hash, 0, 8 );
	    return $hash == self::getPasswordHash( $salt, $password );
	}
 	public static function getHash($password)
 	{
 		return self::getPasswordHash(self::getPasswordSalt(),$password);
 	}
 }